.tree {
  position: relative;
  list-style: none;
  padding: 0;
  margin: 0;

  &:not(:last-child) {
    margin-bottom: 12px;
  }

  .tree__item & {
    padding-left: 8px;
    margin-top: 6px;
  }
}

.tree__item {
  @extend %first-last-no-margin;

  position: relative;
  margin: 2px 0;

  @include rounded($rounded-md);

  &.active {
    background-color: rgba($palette-neutral-1300, 0.04);
  }

  &.tree__item--loading::after {
    content: ' ';

    @include loading(14px);
    @include absolute(8px, 9px, auto, auto);
  }
}

%tree-size {
  line-height: 32px;
}

.tree__action {
  @extend %tree-size;

  padding: 0 8px;

  @include rounded($rounded);

  &.tree__action--disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  &:has(.tree__progress-percentage) {
    padding-right: 72px;
  }

  &:not(.tree__action--disabled):hover {
    background-color: rgba($palette-neutral-1300, 0.04);
  }

  &.tree__action--highlighted {
    background-color: rgba($palette-neutral-1300, 0.04);
  }

  .tree__item.active &:hover {
    background-color: transparent;
  }

  &.tree__action--has-options,
  &.tree__action--has-counter,
  &.tree__action--has-right-icon {
    padding-right: 32px;
  }
}

.tree__link {
  @extend %tree-size;

  color: $palette-neutral-900;

  @include flex-align-items(8px);

  .tree__action--deactivated & {
    color: $palette-neutral-500;
  }

  &:hover {
    text-decoration: none;
  }

  &.tree__link--group {
    font-weight: 600;
  }

  .tree__action--disabled &:hover {
    cursor: inherit;
  }

  &--empty::before {
    @extend %empty;

    left: 24px;
    right: 40px;
    top: 8px;
    height: 16px;
    border-radius: 16px;
  }
}

.tree__link-text {
  @extend %ellipsis;

  display: flex;
  min-width: 0;
  color: $palette-neutral-900;
  font-weight: 500;

  .active & {
    color: $palette-neutral-1200;
  }
}

.tree__progress-percentage {
  display: inline-block;
  position: absolute;
  right: 35px;
  color: $color-primary-500;
}

.tree__icon {
  @extend %tree-size;

  text-align: center;
  color: $palette-neutral-700;
  font-size: 16px;

  .active & {
    color: $palette-neutral-1200;
  }
}

.tree__icon-right {
  margin-left: auto;
  font-size: 14px;
}

%tree-sub-size {
  line-height: 32px;
  height: 32px;
}

.tree__subs {
  position: relative;
  list-style: none;
  padding: 0 0 2px;
  margin: 0;
}

.tree__sub {
  @extend %tree-sub-size;

  position: relative;
  margin: 2px 0 0 21px;

  @include rounded($rounded-md);

  &:hover,
  &.active {
    background-color: rgba($palette-neutral-1300, 0.04);
  }

  &::before,
  &::after {
    content: '';
    position: absolute;
    left: -8px;
  }

  &::before {
    height: 32px;
    border-right: 1px solid $palette-neutral-200;
  }

  &:not(:last-child) {
    margin-bottom: 2px;

    &::before {
      height: 34px;
    }
  }
}

.tree__subs:not(:last-of-type) {
  padding: 0;

  & .tree__sub:last-child::before {
    height: 28px;
  }
}

.tree__sub-link {
  @extend %tree-sub-size;
  @extend %ellipsis;

  color: $palette-neutral-900;
  font-weight: 500;
  padding: 0 32px 0 16px;
  display: flex;
  align-items: center;
  gap: 5px;

  &:hover {
    cursor: pointer;
    text-decoration: none;
  }

  .active > & {
    color: $palette-neutral-1200;
  }

  /* stylelint-disable-next-line */
  &--empty::before {
    @extend %empty;

    left: 32px;
    right: 40px;
    top: 8px;
    height: 14px;
    border-radius: 14px;
  }
}

.tree__sub-link--loading {
  @include loading(14px);
  @include absolute(9px, 9px, auto, auto);
}

.tree__sub-link--disabled {
  opacity: 0.6;
  cursor: not-allowed;

  &:hover {
    color: $color-neutral-900;
    opacity: 0.6;
    text-decoration: none;
    cursor: not-allowed;
  }
}

.tree__sub-add {
  display: inline-block;
  margin: 10px 0 10px 6px;
  line-height: 17px;
  font-size: 12px;
  font-weight: 500;
  color: $palette-neutral-900;

  &:hover {
    text-decoration: none;
    color: $palette-neutral-1200;
  }
}

.tree__sub-add-icon {
  font-size: 16px;
  color: $palette-neutral-600;

  .tree__sub-add:hover & {
    color: $palette-neutral-1200;
  }
}

.tree__right-icon,
%tree-right-icon {
  position: absolute;
  z-index: 1;
  right: 0;
  top: 0;
  bottom: 0;
  max-height: 32px;
  width: 32px;
  color: $color-neutral-700;
  font-size: 16px;
  display: none;
  align-items: center;
  justify-content: center;

  :hover > & {
    display: flex;
  }

  .tree__item--loading > .tree__action > & {
    display: none;
  }
}

.tree__options {
  @extend %tree-right-icon;

  color: $color-neutral-500;
  cursor: pointer;

  &:hover {
    color: $color-neutral-900;
  }
}

.tree__counter {
  position: absolute;
  top: 8px;
  right: 8px;
}

.tree__heading {
  font-size: 11px;
  font-weight: 500;
  color: $palette-neutral-900;
  margin: 8px;
}
